.386
.model flat, stdcall
option casemap:none

include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc

.code
; GetRegString
GetRegString proc stdcall hKey:dword, pszSubKey:dword, pszValueName:dword, pszValue:dword, dwSize:dword
    local pdwDisposition:dword
    local pKey:dword
    local dwType
    mov dwType, REG_SZ
    invoke RegCreateKeyExW,
            hKey,
            pszSubKey,
            NULL,
            NULL,
            REG_OPTION_NON_VOLATILE,
            KEY_QUERY_VALUE,
            NULL,
            addr pKey,
            addr pdwDisposition
    .if eax==ERROR_SUCCESS
        invoke RegQueryValueExW, pKey, pszValueName, NULL, addr dwType, pszValue, dwSize
        invoke RegCloseKey, pKey
    .endif
    ret
GetRegString endp

; SetRegString
SetRegString proc stdcall hKey:dword, pszSubKey:dword, pszValueName:dword, pszValue:dword, dwSize:dword
    local pdwDisposition:dword
    local pKey:dword
    invoke RegCreateKeyExW,
            hKey,
            pszSubKey,
            NULL,
            NULL,
            REG_OPTION_NON_VOLATILE,
            KEY_WRITE,
            NULL,
            addr pKey,
            addr pdwDisposition
    .if eax==ERROR_SUCCESS
        invoke RegSetValueExW, pKey, pszValueName, NULL, REG_SZ, pszValue, dwSize
        invoke RegCloseKey, pKey
    .endif
    ret
SetRegString endp

; GetRegDWord
GetRegDWord proc stdcall hKey:dword, pszSubKey:dword, pszValueName:dword, pdwValue:dword
	local pdwDisposition:dword
	local dwTemp:dword
	local pKey:dword
	local dwWordSize:dword
	DW_SIZE EQU 4
	mov dwWordSize, DW_SIZE
	mov dwTemp, REG_DWORD
	invoke RegCreateKeyExW,
			hKey,
			pszSubKey,
			NULL,
			NULL,
			REG_OPTION_NON_VOLATILE,
			KEY_QUERY_VALUE,
			NULL,
			addr pKey,
			addr pdwDisposition
	.IF eax==ERROR_SUCCESS
		invoke RegQueryValueExW, pKey, pszValueName, NULL, addr dwTemp, pdwValue, addr dwWordSize
		invoke RegCloseKey, pKey
	.ENDIF
    ret
GetRegDWord endp

; SetRegDWord
SetRegDWord proc stdcall hKey:dword, pszSubKey:dword, pszValueName:dword, pdwValue:dword
	local pdwDisposition:dword
	local pKey:dword
	DW_SIZE EQU 4
	invoke RegCreateKeyExW,
			hKey,
			pszSubKey,
			NULL,
			NULL,
			REG_OPTION_NON_VOLATILE,
			KEY_WRITE,
			NULL,
			addr pKey,
			addr pdwDisposition
	.IF eax==ERROR_SUCCESS
		invoke RegSetValueExW, pKey, pszValueName, NULL, REG_DWORD, pdwValue, DW_SIZE
		invoke RegCloseKey, pKey
	.ENDIF
	ret
SetRegDWord endp

end